package com.dkm.biz.ou.repository.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Repository;

import com.dkm.base.core.helper.SpringHelper;
import com.dkm.base.db.persistence.dao.IQueryDao;
import com.dkm.biz.repository.AbstractRepository;
import com.dkm.biz.ou.domain.Addr;
import com.dkm.biz.ou.repository.AddrRepository;
import com.dkm.biz.ou.persistence.dao.AddrQueryDao;
import com.dkm.biz.ou.persistence.entity.AddrPo;

/**
 * 对象功能:参与者地址 Repository接口的实现类
 * 开发公司:dkm.com
 * 开发人员:ZHH
 * 创建时间:2017-05-19 14:26:44
 */
@Repository
public class AddrRepositoryImpl extends AbstractRepository<String, AddrPo,Addr> implements AddrRepository{
	  
	@Resource
	private  AddrQueryDao addrQueryDao;

	public Addr newInstance() {
		AddrPo po = new AddrPo();
		Addr addr = SpringHelper.getBean(Addr.class);
		addr.setData(po);
		return addr;
	}

	public Addr newInstance(AddrPo po) {
		Addr addr = SpringHelper.getBean(Addr.class);
		addr.setData(po);
		return addr;
	} 
	
	@Override
	protected IQueryDao<String, AddrPo> getQueryDao() {
		return addrQueryDao;
	}

	@Override
	public AddrPo findByPartyid(String partyId) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuffer buffer = new StringBuffer();
		buffer.append("party_id_='"+partyId+"'");
		buffer.append(" and type_='shipping' and is_default_='Y'");
		params.put("whereSql", buffer.toString());
		
		List<AddrPo> addrPos = findAll(params);
		if(addrPos.size() > 0){
			AddrPo  addrPo2 = addrPos.get(0);
			return addrPo2;
		}
		return null;
	}
	
}
